#include "3DSpace.h"
#include<iostream>
#include<cmath>
using namespace std;

Vector::Vector()
{
	x = 0;
	y = 0;
	z = 0;
}

Vector::Vector(Point p)
{
	x = p.x;
	y = p.y;
	z = p.z;
}

Vector::Vector(Point p1, Point p2)
{
	x = p1.x - p2.x;
	y = p1.y - p2.y;
	z = p1.z - p2.z;
}

Vector::Vector(double x_, double y_, double z_)
{
	x = x_;
	y = y_;
	z = z_;
}

void Vector::display()
{
	cout << "(" << x << "," << y << "," << z << ")" << endl;
}

Vector Vector::crossProduct(Vector v)
{
	double x_ = y * v.z - v.y * z;
	double y_ = z * v.x - v.z * x;
	double z_ = x * v.y - v.x * y;
	return Vector(x_, y_, z_);
}

double Vector::dotProduct(Vector v)
{
	return x * v.x + y * v.y + z * v.z;
}

Vector Vector::getUnit()
{
	double d = this->getLength();
	return Vector(x / d, y / d, z / d);
}

bool Vector::isSameDir(Vector v)
{
	if ((x <= 1e-6 && v.x <= 1e-6)||(y <= 1e-6 && v.y <= 1e-6)||(z <= 1e-6 && v.z <= 1e-6))
		return true;
	if ((x / v.x - y / v.y) <= 1e-6 && (x / v.x - z / v.z) <= 1e-6)
		return true;
	else
		return false;
}

double Vector::getLength()
{
	return sqrt(x * x + y * y + z * z);
}
